<?php
include "../service/userService.php";

if(isset($_POST["user"])){
    if(!checkUserAvailable($_POST["user"]))
    {
        $user['username'] = $_POST["user"];
        $user['pwd'] = $_POST["pwd"];
        $user['sex'] = $_POST["sex"];
        $user['dob'] = $_POST["dob"];
        $imgNum = date("Y").date("m").date("d").date("h").date("i").date("s");
        $imgType = str_replace("image/",".",$_FILES["file"]["type"]);
        $user['avatar'] = $imgNum.$imgType;
        $user['phone'] = $_POST["phone"];
        $user['add'] = $_POST["add"];
        $user['email'] = $_POST["email"];
        $user['descript'] = $_POST["descript"];
        $user['createdate'] = date("Y")."-".date("m")."-".date("d");
        $user['type'] = $_POST["type"];
        $location = "pc";
        $phpName = "register";
        if($user['type'] == 2){
            $location = "admin";
            $phpName = "registerMOD";
            $result = insertModerator($user);
        }  
        else if ($user['type'] == 3)
            $result = insertNormaluser($user);
        else if ($user['type'] == 4)
            $result = insertCompany($user);
        if($result){
            if ((($_FILES["file"]["type"] == "image/gif")
            || ($_FILES["file"]["type"] == "image/jpeg")
            || ($_FILES["file"]["type"] == "image/pjpeg"))
            && ($_FILES["file"]["size"] < 200000))
            {move_uploaded_file($_FILES["file"]["tmp_name"],"../upload/" . $imgNum . $imgType);}
            echo "<script>window.location.href='../".$location."/".$phpName.".php?msg=0'</script>";
        }
        else
            echo "<script>window.location.href='../".$location."/".$phpName.".php?msg=1'</script>";
    }
}


mysql_close($conn);
?>